<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="stable/static/css/site.css" rel="stylesheet" type="text/css">
    <link href="stable/static/css/print.css" rel="stylesheet" type="text/css" media="print">
    <link href="stable/static/css/prettify.css" rel="stylesheet" type="text/css">
    <link href="//www.google.com/images/icons/product/chrome-16.png" rel="icon" type="image/ico">
    <link href="stable/static/css/api.css" rel="stylesheet" type="text/css">
    <title>chrome.extension - chrome插件中文开发文档(非官方)</title>
  </head>
  <body>
    <a id="top"></a>
    <div id="header">{Header content}</div>
    <a id="gc-topnav-anchor"></a>
    <div id="gc-topnav">
      <h1>Google Chrome Extensions</h1>
      <ul id="home" class="gc-topnav-tabs">
        <li id="home_link">
          <a href="index.html" title="Google Chrome Extensions home page"><div>Home</div></a>
        </li>
        <li id="docs_link">
          <a href="docs.html" title="Official Google Chrome Extensions documentation"><div>Docs</div></a>
        </li>
        <li id="faq_link">
          <a href="faq.html" title="Answers to frequently asked questions about Google Chrome Extensions"><div>FAQ</div></a>
        </li>
        <li id="samples_link">
          <a href="samples.html" title="Sample Extensions (with source code)"><div>Samples</div></a>
        </li>
        <li id="group_link">
          <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions" title="Google Chrome Extensions developer forum"><div>Group</div></a>
        </li>
        <li id="so_link">
          <a href="http://stackoverflow.com/questions/tagged/google-chrome-extension" title="[google-chrome-extension] tag on Stack Overflow"><div>Questions?</div></a>
        </li>
      </ul>
    </div>
    <div id="gc-container">
      <div id="gc-sidebar">
        <ul 
            class="level1 ">
          <li class="level2">
                <a href="getstarted.html" class="level2 ">Getting Started</a>
          </li>
          <li class="level2">
                <a href="overview.html" class="level2 ">Overview</a>
          </li>
          <li class="level2">
                <a href="whats_new.html" class="level2 ">What's New?</a>
          </li>
          <li class="level2">
                <a href="devguide.html" class="level2 ">Developer's Guide</a>
              <ul 
                  class="level2 ">
                <li class="level3">
                    <a class="button level3">
                      <span class="level3">Browser UI</span>
                      <div class="toggleIndicator level3"></div>
                    </a>
                    <ul toggleable
                        class="level3 hidden">
                      <li class="level4">
                            <a href="browserAction.html" class="level4 ">Browser Actions</a>
                      </li>
                      <li class="level4">
                            <a href="contextMenus.html" class="level4 ">Context Menus</a>
                      </li>
                      <li class="level4">
                            <a href="notifications.html" class="level4 ">Desktop Notifications</a>
                      </li>
                      <li class="level4">
                            <a href="omnibox.html" class="level4 ">Omnibox</a>
                      </li>
                      <li class="level4">
                            <a href="options.html" class="level4 ">Options Pages</a>
                      </li>
                      <li class="level4">
                            <a href="override.html" class="level4 ">Override Pages</a>
                      </li>
                      <li class="level4">
                            <a href="pageAction.html" class="level4 ">Page Actions</a>
                      </li>
                    </ul>
                </li>
                <li class="level3">
                    <a class="button level3">
                      <span class="level3">Browser Interaction</span>
                      <div class="toggleIndicator level3"></div>
                    </a>
                    <ul toggleable
                        class="level3 hidden">
                      <li class="level4">
                            <a href="bookmarks.html" class="level4 ">Bookmarks</a>
                      </li>
                      <li class="level4">
                            <a href="cookies.html" class="level4 ">Cookies</a>
                      </li>
                      <li class="level4">
                            <a href="devtools.html" class="level4 ">Developer Tools</a>
                      </li>
                      <li class="level4">
                            <a href="events.html" class="level4 ">Events</a>
                      </li>
                      <li class="level4">
                            <a href="history.html" class="level4 ">History</a>
                      </li>
                      <li class="level4">
                            <a href="management.html" class="level4 ">Management</a>
                      </li>
                      <li class="level4">
                            <a href="tabs.html" class="level4 ">Tabs</a>
                      </li>
                      <li class="level4">
                            <a href="windows.html" class="level4 ">Windows</a>
                      </li>
                    </ul>
                </li>
                <li class="level3">
                    <a class="button level3">
                      <span class="level3">Implementation</span>
                      <div class="toggleIndicator level3"></div>
                    </a>
                    <ul toggleable
                        class="level3 hidden">
                      <li class="level4">
                            <a href="a11y.html" class="level4 ">Accessibility</a>
                      </li>
                      <li class="level4">
                            <a href="event_pages.html" class="level4 ">Event Pages</a>
                      </li>
                      <li class="level4">
                            <a href="contentSecurityPolicy.html" class="level4 ">Content Security Policy</a>
                      </li>
                      <li class="level4">
                            <a href="content_scripts.html" class="level4 ">Content Scripts</a>
                      </li>
                      <li class="level4">
                            <a href="xhr.html" class="level4 ">Cross-Origin XHR</a>
                      </li>
                      <li class="level4">
                            <a href="i18n.html" class="level4 ">Internationalization</a>
                      </li>
                      <li class="level4">
                            <a href="messaging.html" class="level4 ">Message Passing</a>
                      </li>
                      <li class="level4">
                            <a href="permissions.html" class="level4 ">Optional Permissions</a>
                      </li>
                      <li class="level4">
                            <a href="npapi.html" class="level4 ">NPAPI Plugins</a>
                      </li>
                    </ul>
                </li>
                <li class="level3">
                    <a class="button level3">
                      <span class="level3">Finishing</span>
                      <div class="toggleIndicator level3"></div>
                    </a>
                    <ul toggleable
                        class="level3 hidden">
                      <li class="level4">
                            <a href="hosting.html" class="level4 ">Hosting</a>
                      </li>
                      <li class="level4">
                            <a href="external_extensions.html" class="level4 ">Other Deployment Options</a>
                      </li>
                    </ul>
                </li>
              </ul>
          </li>
          <li class="level2">
                <a href="tutorials.html" class="level2 ">Tutorials</a>
              <ul 
                  class="level2 ">
                <li class="level3">
                      <a href="tut_migration_to_manifest_v2.html" class="level3 ">Manifest V2</a>
                </li>
                <li class="level3">
                      <a href="tut_debugging.html" class="level3 ">Debugging</a>
                </li>
                <li class="level3">
                      <a href="tut_analytics.html" class="level3 ">Google Analytics</a>
                </li>
                <li class="level3">
                      <a href="tut_oauth.html" class="level3 ">OAuth</a>
                </li>
              </ul>
          </li>
          <li class="level2">
                <span class="level2">Reference</span>
              <ul 
                  class="level2 ">
                <li class="level3">
                    <a class="button level3">
                      <span class="level3">Formats</span>
                      <div class="toggleIndicator level3"></div>
                    </a>
                    <ul toggleable
                        class="level3 hidden">
                      <li class="level4">
                            <a href="manifest.html" class="level4 ">Manifest Files</a>
                      </li>
                      <li class="level4">
                            <a href="match_patterns.html" class="level4 ">Match Patterns</a>
                      </li>
                    </ul>
                </li>
                <li class="level3">
                      <a href="permission_warnings.html" class="level3 ">Permission Warnings</a>
                </li>
                <li class="level3">
                      <a href="api_index.html" class="level3 ">chrome.* APIs</a>
                </li>
                <li class="level3">
                      <a href="api_other.html" class="level3 ">Other APIs</a>
                </li>
              </ul>
          </li>
          <li class="level2">
                <span class="level2">More</span>
              <ul 
                  class="level2 ">
                <li class="level3">
                      <a href="http://code.google.com/chrome/webstore/docs/index.html" class="level3 ">Chrome Web Store</a>
                </li>
                <li class="level3">
                      <a href="http://code.google.com/chrome/apps/docs/developers_guide.html" class="level3 ">Hosted Apps</a>
                </li>
                <li class="level3">
                      <a href="themes.html" class="level3 ">Themes</a>
                </li>
              </ul>
          </li>
        </ul>
      </div>
      <div id="gc-pagecontent">
        <h1 class="page_title">chrome.extension</h1>
        
        
        
        <div id="toc">
          <h2>Contents</h2>
          <ol>
            <li>
              <a href=#content scripts>Support for content scripts</a>
            </li>
            <li>
              <a href="#apiReference">API reference: chrome.extension</a>
              <ol>
                  <li><a href="#types">Types</a><ol>  <li>    <a href="#type-MessageSender">MessageSender</a>  </li>  <li>    <a href="#type-Port">Port</a>  </li></ol></li>
                  <li><a href="#properties">Properties</a><ol>  <li>    <a href="#property-lastError">lastError</a><ol><li>      <a href="#lastError-properties">Properties</a>      <ol>        <li>          <a href="#property-lastError-message">message</a>        </li>      </ol>    </li></ol>  </li>  <li>    <a href="#property-inIncognitoContext">inIncognitoContext</a>  </li></ol></li>
                  <li><a href="#methods">Methods</a><ol>  <li><a href="#method-connect">connect</a></li>  <li><a href="#method-sendMessage">sendMessage</a></li>  <li><a href="#method-getURL">getURL</a></li>  <li><a href="#method-getViews">getViews</a></li>  <li><a href="#method-getBackgroundPage">getBackgroundPage</a></li>  <li><a href="#method-isAllowedIncognitoAccess">isAllowedIncognitoAccess</a></li>  <li><a href="#method-isAllowedFileSchemeAccess">isAllowedFileSchemeAccess</a></li>  <li><a href="#method-setUpdateUrlData">setUpdateUrlData</a></li></ol></li>
                  <li><a href="#events">Events</a><ol>  <li><a href="#event-onConnect">onConnect</a></li>  <li><a href="#event-onConnectExternal">onConnectExternal</a></li>  <li><a href="#event-onMessage">onMessage</a></li>  <li><a href="#event-onMessageExternal">onMessageExternal</a></li></ol></li>
                  <li><a href="#samples">Sample Extensions</a></li>
              </ol>
            </li>
          </ol>
        </div>

<p id="classSummary">
The <code>chrome.extension</code> module
has utilities that can be used by any extension page.
It includes support for exchanging messages
between an extension and its content scripts
or between extensions,
as described in detail in
<a href="messaging.html">Message Passing</a>.
</p>

<h2 id="content scripts">Support for content scripts</h2>
<p>
Unlike the other chrome.* APIs,
parts of <code>chrome.extension</code>
can be used by content scripts:
</p>

<dl>
  <dt>
    <a href="#method-sendMessage"><code>sendMessage()</code></a> and
    <a href="#event-onMessage"><code>onMessage</code></a>
  </dt>
  <dd>
    Simple communication with extension pages
  </dd>
  <dt>
    <a href="#method-connect"><code>connect()</code></a> and
    <a href="#event-onConnect"><code>onConnect</code></a>
  </dt>
  <dd>
    Extended communication with extension pages
  </dd>
  <dt>
    <a href="#method-getURL"><code>getURL()</code></a>
  </dt>
  <dd>
    Access to extension resources such as image files
  </dd>
</dl>

<p>
For details, see
<a href="content_scripts.html">Content Scripts</a>.
</p>
        <h2 id="apiReference">API Reference: chrome.extension</h2>
        <div class="api_reference">
            <h3 id="types">Types</h3>
              <div>
                <h3 id="type-MessageSender">MessageSender</h3>
                <div>
                  <dt><span class="type_name">  (    <span id="typeTemplate">object</span>  )</span></dt>
              <dd>
                    An object containing information about the script context that sent a message or request.
                  </dd>    <h4 id="MessageSender-properties">
                    Properties of <a href="#type-MessageSender">MessageSender</a>
                  </h4>
                  <dd><dl>      <div>
                      <a name="property-MessageSender-tab"></a>
                      <dt>
                        <span class="variable">tab</span>
                        <span class="property">
                          (
                            <span class="optional">optional</span>
                            <span id="typeTemplate"><a href="tabs.html#type-Tab">tabs.Tab</a></span>
                          )
                        </span>
                      </dt>
                      <dd>
                        This property will <b>only</b> be present when the connection was opened from a tab or content script.
                      </dd>
                    </div>
                    <div>
                      <a name="property-MessageSender-id"></a>
                      <dt>
                        <span class="variable">id</span>
                        <span class="property">
                          (
                            
                            <span id="typeTemplate">string</span>
                          )
                        </span>
                      </dt>
                      <dd>
                        The extension ID of the extension that opened the connection.
                      </dd>
                    </div>
              </dl></dd>
                </div>
              </div>
              <div>
                <h3 id="type-Port">Port</h3>
                <div>
                  <dt><span class="type_name">  (    <span id="typeTemplate">object</span>  )</span></dt>
              <dd>
                    An object which allows two way communication with other pages.
                  </dd>    <h4 id="Port-properties">
                    Properties of <a href="#type-Port">Port</a>
                  </h4>
                  <dd><dl>      <div>
                      <a name="property-Port-name"></a>
                      <dt>
                        <span class="variable">name</span>
                        <span class="property">
                          (
                            
                            <span id="typeTemplate">string</span>
                          )
                        </span>
                      </dt>
                    </div>
                    <div>
                      <a name="property-Port-onDisconnect"></a>
                      <dt>
                        <span class="variable">onDisconnect</span>
                        <span class="property">
                          (
                            
                            <span id="typeTemplate"><a href="events.html#type-Event">events.Event</a></span>
                          )
                        </span>
                      </dt>
                    </div>
                    <div>
                      <a name="property-Port-onMessage"></a>
                      <dt>
                        <span class="variable">onMessage</span>
                        <span class="property">
                          (
                            
                            <span id="typeTemplate"><a href="events.html#type-Event">events.Event</a></span>
                          )
                        </span>
                      </dt>
                    </div>
                    <div>
                      <a name="property-Port-postMessage"></a>
                      <dt>
                        <span class="variable">postMessage</span>
                        <span class="property">
                          (
                            
                            <span id="typeTemplate">function</span>
                          )
                        </span>
                      </dt>
                    </div>
                    <div>
                      <a name="property-Port-sender"></a>
                      <dt>
                        <span class="variable">sender</span>
                        <span class="property">
                          (
                            <span class="optional">optional</span>
                            <span id="typeTemplate"><a href="extension.html#type-MessageSender">MessageSender</a></span>
                          )
                        </span>
                      </dt>
                      <dd>
                        This property will <b>only</b> be present on ports passed to onConnect/onConnectExternal listeners.
                      </dd>
                    </div>
              </dl></dd>
                </div>
              </div>
            <h3 id="properties">Properties</h3>
              <div>
                <h3 id="property-lastError">lastError</h3>
                <div class="summary">
                  <span>chrome.extension.lastError</span>
                </div>
                <div>
                  <dt><span class="property">lastError</span> <span class="type_name">  (  <span class="optional">optional</span>  <span id="typeTemplate">object</span>  )</span></dt>
              <dd>
                    Set for the lifetime of a callback if an ansychronous extension api has resulted in an error. If no error has occured lastError will be <var>undefined</var>.
                  </dd>    <h4 id="lastError-properties">
                    Properties of <a href="#property-lastError">lastError</a>
                  </h4>
                  <dd><dl>      <div>
                      <a name="property-lastError-message"></a>
                      <dt>
                        <span class="variable">message</span>
                        <span class="property">
                          (
                            
                            <span id="typeTemplate">string</span>
                          )
                        </span>
                      </dt>
                      <dd>
                        Description of the error that has taken place.
                      </dd>
                    </div>
              </dl></dd>
                </div>
              </div>
              <div>
                <h3 id="property-inIncognitoContext">inIncognitoContext</h3>
                <div class="summary">
                  <span>chrome.extension.inIncognitoContext</span>
                </div>
                <div>
                  <dt><span class="property">inIncognitoContext</span> <span class="type_name">  (  <span class="optional">optional</span>  <span id="typeTemplate">boolean</span>  )</span></dt>
              <dd>
                    True for content scripts running inside incognito tabs, and for extension pages running inside an incognito process. The latter only applies to extensions with 'split' incognito_behavior.
                  </dd>  </div>
              </div>
            <h3 id="methods">Methods</h3>
              <div>
                <h4 id="method-connect">connect</h4>
                <div class="summary">
                  <span><a href="extension.html#type-Port">Port</a> chrome.extension.connect</span>(<span class="optional">string <span class="variable">extensionId</span></span>, <span class="optional">object <span class="variable">connectInfo</span></span>)
                </div>
                <div class="description">
              <p>
                    Attempts to connect to other listeners within the extension (such as the extension's background page). This is primarily useful for content scripts connecting to their extension processes. Note that this does not connect to any listeners in a content script. Extensions may connect to content scripts embedded in tabs via <a href='tabs.html#method-connect'><code>chrome.tabs.connect()</code></a>.
                  </p>    <h4>Parameters</h4>
                  <dl>
                    <div>  <a name="property-connect-extensionId"></a>  <dt>    <span class="variable">extensionId</span>    <span class="property">      (        <span class="optional">optional</span>        <span id="typeTemplate">string</span>      )    </span>  </dt>  <dd>    The extension ID of the extension you want to connect to. If omitted, default is your own extension.  </dd></div><div>  <a name="property-connect-connectInfo"></a>  <dt>    <span class="variable">connectInfo</span>    <span class="property">      (        <span class="optional">optional</span>        <span id="typeTemplate">object</span>      )    </span>  </dt>  <dd>    <dl>      <div>        <a name="property-connectInfo-name"></a>        <dt>          <span class="variable">name</span>          <span class="property">            (              <span class="optional">optional</span>              <span id="typeTemplate">string</span>            )          </span>        </dt>        <dd>          Will be passed into onConnect for extension processes that are listening for the connection event.        </dd>      </div>    </dl>  </dd></div>
                  </dl>
                  
                </div>
              </div>
              <div>
                <h4 id="method-sendMessage">sendMessage</h4>
                <div class="summary lower">
                  <span>chrome.extension.sendMessage</span>(<span class="optional">string <span class="variable">extensionId</span></span>, <span>any <span class="variable">message</span></span>)
                </div>
                <div class="description">
              <p>
                    Sends a single message to other listeners within the extension. Similar to chrome.extension.connect, but only sends a single message with an optional response. The <a href='extension.html#event-onMessage'>chrome.extension.onMessage</a> event is fired in each extension page of the extension. Note that extensions cannot send messages to content scripts using this method. To send messages to content scripts, use <a href='tabs.html#method-sendMessage'><code>chrome.tabs.sendMessage()</code></a>.
                  </p>    <h4>Parameters</h4>
                  <dl>
                    <div>  <a name="property-sendMessage-extensionId"></a>  <dt>    <span class="variable">extensionId</span>    <span class="property">      (        <span class="optional">optional</span>        <span id="typeTemplate">string</span>      )    </span>  </dt>  <dd>    The extension ID of the extension you want to connect to. If omitted, default is your own extension.  </dd></div><div>  <a name="property-sendMessage-message"></a>  <dt>    <span class="variable">message</span>    <span class="property">      (                <span id="typeTemplate">any</span>      )    </span>  </dt></div>
                  </dl>
                  <h4>Callback function</h4><p>      If you specify the <em>responseCallback</em> parameter, it should      specify a function that looks like this:</p><pre>function(any response) <span class="subdued">{...}</span>;</pre><dl>  <div>  <a name="property-responseCallback-response"></a>  <dt>    <span class="variable">response</span>    <span class="property">      (                <span id="typeTemplate">any</span>      )    </span>  </dt>  <dd>    The JSON response object sent by the handler of the message. If an error occurs while connecting to the extension, the callback will be called with no arguments and <a href='extension.html#property-lastError'>chrome.extension.lastError</a> will be set to the error message.  </dd></div></dl>
                </div>
              </div>
              <div>
                <h4 id="method-getURL">getURL</h4>
                <div class="summary">
                  <span>string chrome.extension.getURL</span>(<span>string <span class="variable">path</span></span>)
                </div>
                <div class="description">
              <p>
                    Converts a relative path within an extension install directory to a fully-qualified URL.
                  </p>    <h4>Parameters</h4>
                  <dl>
                    <div>  <a name="property-getURL-path"></a>  <dt>    <span class="variable">path</span>    <span class="property">      (                <span id="typeTemplate">string</span>      )    </span>  </dt>  <dd>    A path to a resource within an extension expressed relative to its install directory.  </dd></div>
                  </dl>
                  
                </div>
              </div>
              <div>
                <h4 id="method-getViews">getViews</h4>
                <div class="summary">
                  <span>array of global chrome.extension.getViews</span>(<span class="optional">object <span class="variable">fetchProperties</span></span>)
                </div>
                <div class="description">
              <p>
                    Returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension.
                  </p>    <h4>Parameters</h4>
                  <dl>
                    <div>  <a name="property-getViews-fetchProperties"></a>  <dt>    <span class="variable">fetchProperties</span>    <span class="property">      (        <span class="optional">optional</span>        <span id="typeTemplate">object</span>      )    </span>  </dt>  <dd>    <dl>      <div>        <a name="property-fetchProperties-type"></a>        <dt>          <span class="variable">type</span>          <span class="property">            (              <span class="optional">optional</span>              <span id="typeTemplate">enumerated string ["tab", "infobar", "notification", "popup"]</span>            )          </span>        </dt>        <dd>          The type of view to get. If omitted, returns all views (including background pages and tabs). Valid values: 'tab', 'infobar', 'notification', 'popup'.        </dd>      </div>      <div>        <a name="property-fetchProperties-windowId"></a>        <dt>          <span class="variable">windowId</span>          <span class="property">            (              <span class="optional">optional</span>              <span id="typeTemplate">integer</span>            )          </span>        </dt>        <dd>          The window to restrict the search to. If omitted, returns all views.        </dd>      </div>    </dl>  </dd></div>
                  </dl>
                  
                </div>
              </div>
              <div>
                <h4 id="method-getBackgroundPage">getBackgroundPage</h4>
                <div class="summary">
                  <span>global chrome.extension.getBackgroundPage</span>()
                </div>
                <div class="description">
              <p>
                    Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page.
                  </p>  </div>
              </div>
              <div>
                <h4 id="method-isAllowedIncognitoAccess">isAllowedIncognitoAccess</h4>
                <div class="summary lower">
                  <span>chrome.extension.isAllowedIncognitoAccess</span>()
                </div>
                <div class="description">
              <p>
                    Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox.
                  </p>  </div>
              </div>
              <div>
                <h4 id="method-isAllowedFileSchemeAccess">isAllowedFileSchemeAccess</h4>
                <div class="summary lower">
                  <span>chrome.extension.isAllowedFileSchemeAccess</span>()
                </div>
                <div class="description">
              <p>
                    Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.
                  </p>  </div>
              </div>
              <div>
                <h4 id="method-setUpdateUrlData">setUpdateUrlData</h4>
                <div class="summary lower">
                  <span>chrome.extension.setUpdateUrlData</span>(<span>string <span class="variable">data</span></span>)
                </div>
                <div class="description">
              <p>
                    Sets the value of the ap CGI parameter used in the extension's update URL.  This value is ignored for extensions that are hosted in the Chrome Extension Gallery.
                  </p>    <h4>Parameters</h4>
                  <dl>
                    <div>  <a name="property-setUpdateUrlData-data"></a>  <dt>    <span class="variable">data</span>    <span class="property">      (                <span id="typeTemplate">string</span>      )    </span>  </dt></div>
                  </dl>
                  
                </div>
              </div>
            <h3 id="events">Events</h3>
              <div>
                <h4 id="event-onConnect">onConnect</h4>
                <div class="summary">
                  <span class="subdued">chrome.extension.</span>onConnect<span class="subdued">.addListener</span>(function(<span><a href="extension.html#type-Port">Port</a> <span class="variable">port</span></span>)<span class="subdued"> {...}</span>);
                </div>
                <div class="description">
              <p>
                    Fired when a connection is made from either an extension process or a content script.
                  </p>      <h4>Listener Parameters</h4>
                    <dl>
                      <div>  <a name="property-onConnect-port"></a>  <dt>    <span class="variable">port</span>    <span class="property">      (                <span id="typeTemplate"><a href="extension.html#type-Port">Port</a></span>      )    </span>  </dt></div>
                    </dl>
                </div>
              </div>
              <div>
                <h4 id="event-onConnectExternal">onConnectExternal</h4>
                <div class="summary">
                  <span class="subdued">chrome.extension.</span>onConnectExternal<span class="subdued">.addListener</span>(function(<span><a href="extension.html#type-Port">Port</a> <span class="variable">port</span></span>)<span class="subdued"> {...}</span>);
                </div>
                <div class="description">
              <p>
                    Fired when a connection is made from another extension.
                  </p>      <h4>Listener Parameters</h4>
                    <dl>
                      <div>  <a name="property-onConnectExternal-port"></a>  <dt>    <span class="variable">port</span>    <span class="property">      (                <span id="typeTemplate"><a href="extension.html#type-Port">Port</a></span>      )    </span>  </dt></div>
                    </dl>
                </div>
              </div>
              <div>
                <h4 id="event-onMessage">onMessage</h4>
                <div class="summary">
                  <span class="subdued">chrome.extension.</span>onMessage<span class="subdued">.addListener</span>(function(<span>any <span class="variable">message</span></span>, <span><a href="extension.html#type-MessageSender">MessageSender</a> <span class="variable">sender</span></span>)<span class="subdued"> {...}</span>);
                </div>
                <div class="description">
              <p>
                    Fired when a message is sent from either an extension process or a content script.
                  </p>      <h4>Listener Parameters</h4>
                    <dl>
                      <div>  <a name="property-onMessage-message"></a>  <dt>    <span class="variable">message</span>    <span class="property">      (                <span id="typeTemplate">any</span>      )    </span>  </dt>  <dd>    The message sent by the calling script.  </dd></div><div>  <a name="property-onMessage-sender"></a>  <dt>    <span class="variable">sender</span>    <span class="property">      (                <span id="typeTemplate"><a href="extension.html#type-MessageSender">MessageSender</a></span>      )    </span>  </dt></div>
                    </dl>
                    <h4>Callback function</h4>
                    <p>
                          The <em>sendResponse</em> parameter should specify a function
                          that looks like this:
                    </p>
                    <pre>function() <span class="subdued">{...}</span>;</pre>
                    <dl>
                      
                    </dl>
                </div>
              </div>
              <div>
                <h4 id="event-onMessageExternal">onMessageExternal</h4>
                <div class="summary">
                  <span class="subdued">chrome.extension.</span>onMessageExternal<span class="subdued">.addListener</span>(function(<span>any <span class="variable">message</span></span>, <span><a href="extension.html#type-MessageSender">MessageSender</a> <span class="variable">sender</span></span>)<span class="subdued"> {...}</span>);
                </div>
                <div class="description">
              <p>
                    Fired when a message is sent from another extension.
                  </p>      <h4>Listener Parameters</h4>
                    <dl>
                      <div>  <a name="property-onMessageExternal-message"></a>  <dt>    <span class="variable">message</span>    <span class="property">      (                <span id="typeTemplate">any</span>      )    </span>  </dt>  <dd>    The message sent by the calling script.  </dd></div><div>  <a name="property-onMessageExternal-sender"></a>  <dt>    <span class="variable">sender</span>    <span class="property">      (                <span id="typeTemplate"><a href="extension.html#type-MessageSender">MessageSender</a></span>      )    </span>  </dt></div>
                    </dl>
                    <h4>Callback function</h4>
                    <p>
                          The <em>sendResponse</em> parameter should specify a function
                          that looks like this:
                    </p>
                    <pre>function() <span class="subdued">{...}</span>;</pre>
                    <dl>
                      
                    </dl>
                </div>
              </div>
        </div>
          <h2 id="samples">Sample Extensions that use chrome.extension</h2>
            <li><strong><a href="samples.html#ea5374398da2255f743fd37964100fed">Context Menus Sample</a></strong> &ndash;
            Shows some of the features of the Context Menus API
        </li>
            <li><strong><a href="samples.html#e0410b3575a19930b8cf73f1e5acee0a">Context Menus Sample (with Event Page)</a></strong> &ndash;
            Shows some of the features of the Context Menus API using an event page
        </li>
            <li><strong><a href="samples.html#2b0f7d02f3ebd51358ed54ef59dceebb">Cookie API Test Extension</a></strong> &ndash;
            Testing Cookie API
        </li>
            <li><strong><a href="samples.html#f447d4d0c667a4f72ef8c6190e7925d7">Live HTTP headers</a></strong> &ndash;
            Displays the live log with the http requests headers
        </li>
            <li><strong><a href="samples.html#812b7fe611113aedf0a394e9fbbfcce1">JavaScript pause/resume</a></strong> &ndash;
            Pauses / resumes JavaScript execution
        </li>
            <li><strong><a href="samples.html#d5d930bdcf3f5e1753d0de5924a89a65">Event Page Example</a></strong> &ndash;
            Demonstrates usage and features of the event page
        </li>
            <li><strong><a href="samples.html#07f27750d548befdcdaef589017d9631">`extension.isAllowedFileSchemeAccess` and `extension.isAllowedIncognitoAccess` Example</a></strong> &ndash;
            Demonstrates the `extension.isAllowedFileSchemeAccess` and `extesion.isAllowedIncognitoAccess` APIs
        </li>
            <li><strong><a href="samples.html#b7ee031d2bfdbdd1c89f2cff6ed9781c">Idle - Simple Example</a></strong> &ndash;
            Demonstrates the Idle API
        </li>
            <li><strong><a href="samples.html#2a0bb0bb3a9934a7915ccc7cd640f8ec">Message Timer</a></strong> &ndash;
            Times how long it takes to send a message to a content script and back.
        </li>
            <li><strong><a href="samples.html#bad5f7136687125becc69911eb43ed26">Block/allow third-party cookies API example extension</a></strong> &ndash;
            Sample extension which demonstrates how to access a preference.
        </li>
            <li><strong><a href="samples.html#d16e42e2f0a05f98f31406d425da538e">Block/allow referrer API example extension</a></strong> &ndash;
            Sample extension which demonstrates how to access a preference.
        </li>
            <li><strong><a href="samples.html#00294fafee1df479cc20247741f44447">Speech Recognizer</a></strong> &ndash;
            Recognizes your speech and tells you the most likely result.
        </li>
            <li><strong><a href="samples.html#3680ae406d5eb5fd580b19a93b88b6bf">Stylizr</a></strong> &ndash;
            Spruce up your pages with custom CSS.
        </li>
            <li><strong><a href="samples.html#062d24295dce5def19f91da9c449e1e4">Tab Inspector</a></strong> &ndash;
            Utility for working with the extension tabs api
        </li>
            <li><strong><a href="samples.html#dcc956ee1308eb125ff32bdaad4c1d84">Test Screenshot Extension</a></strong> &ndash;
            Demonstrate screenshot functionality in the chrome.tabs api. Note: only works for code.google.com
        </li>
            <li><strong><a href="samples.html#ada4d65f29289c46d04a1920af682232">Console TTS Engine</a></strong> &ndash;
            A "silent" TTS engine that prints text to a small window rather than synthesizing speech.
        </li>
            <li><strong><a href="samples.html#461b3e0c33d8370c83997cbb9e4e47b7">App Launcher</a></strong> &ndash;
        </li>
            <li><strong><a href="samples.html#a4adef17601281fa9ae9cec08590c7b2">Page Benchmarker</a></strong> &ndash;
            Chromium Page Benchmarker.
        </li>
            <li><strong><a href="samples.html#9fa1c6ac42d625c3f62314548468640c">Chromium Buildbot Monitor</a></strong> &ndash;
            Displays the status of the Chromium buildbot in the toolbar.  Click to see more detailed status in a popup.
        </li>
            <li><strong><a href="samples.html#d85d53e2433c9325f85336791560a68c">Google Calendar Checker (by Google)</a></strong> &ndash;
            Quickly see the time until your next meeting from any of your calendars. Click on the button to be taken to your calendar.
        </li>
            <li><strong><a href="samples.html#ecc227966949f60af19c444222a775d9">Catifier</a></strong> &ndash;
            Moar cats!
        </li>
            <li><strong><a href="samples.html#4e61966db98ebfc75fa32b5ff2406c6b">Email this page (by Google)</a></strong> &ndash;
            This extension adds an email button to the toolbar which allows you to email the page link using your default mail client or Gmail.
        </li>
            <li><strong><a href="samples.html#e9ecdf298b120a99b7a50cd4871c0f83">Chrome Sounds</a></strong> &ndash;
            Enjoy a more magical and immersive experience when browsing the web using the power of sound.
        </li>
            <li><strong><a href="samples.html#76455c1d015bafc204858bee2d4f87e0">Google Document List Viewer</a></strong> &ndash;
            Demonstrates how to use OAuth to connect the Google Documents List Data API.
        </li>
            <li><strong><a href="samples.html#5139d19c542e2188a42418c27c9cdd5b">Google Mail Checker</a></strong> &ndash;
            Displays the number of unread messages in your Google Mail inbox. You can also click the button to open your inbox.
        </li>
            <li><strong><a href="samples.html#4042eaccda909714a2b78cfe60d59b9f">Mappy</a></strong> &ndash;
            Finds addresses in the web page you're on and pops up a map window.
        </li>
            <li><strong><a href="samples.html#87133c06d75da1d316996299bddd7bd1">News Reader (by Google)</a></strong> &ndash;
            Displays the latest stories from Google News in a popup.
        </li>
            <li><strong><a href="samples.html#fd0e71a56fc3e6c5ebe1d5daa3049120">Sample - OAuth Contacts</a></strong> &ndash;
            Uses OAuth to connect to Google's contacts service and display a list of your contacts.
        </li>
            <li><strong><a href="samples.html#fca4e590e0afe37428e5724d34f3a5b3">Per-plugin content settings</a></strong> &ndash;
            Customize your content setting for different plug-ins.
        </li>
            <li><strong><a href="samples.html#bea7f3606e50b59b0f8b08cbab6236da">Proxy Extension API Sample</a></strong> &ndash;
            Set Chrome-specific proxies; a demonstration of Chrome's Proxy API
        </li>
            <li><strong><a href="samples.html#fe3bfa0dd0b9d2a0aab933bd6d3aab88">Speak Selection</a></strong> &ndash;
            Speaks the current selection out loud.
        </li>
            <li><strong><a href="samples.html#bba3c3de3da89e7a53b56bac8a173c3c">Talking Alarm Clock</a></strong> &ndash;
            A clock with two configurable alarms that will play a sound and speak a phrase of your choice.
        </li>
            <li><strong><a href="samples.html#8774186b22c7efb19317611dc01dce1b">TTS Demo</a></strong> &ndash;
            Demo Chrome's synthesized text-to-speech capabilities.
        </li>
      </div>
    </div>
  </body>
  <script>
    window.bootstrap = {
      api_names: [{"name":"alarms"},{"name":"bookmarks"},{"name":"browserAction"},{"name":"browsingData"},{"name":"commands"},{"name":"contentSettings"},{"name":"contextMenus"},{"name":"cookies"},{"name":"debugger"},{"name":"declarativeWebRequest"},{"name":"devtools.inspectedWindow"},{"name":"devtools.network"},{"name":"devtools.panels"},{"name":"downloads"},{"name":"events"},{"name":"extension"},{"name":"fileBrowserHandler"},{"name":"fontSettings"},{"name":"history"},{"name":"i18n"},{"name":"idle"},{"name":"input.ime"},{"name":"management"},{"name":"omnibox"},{"name":"pageAction"},{"name":"pageCapture"},{"name":"permissions"},{"name":"privacy"},{"name":"proxy"},{"name":"runtime"},{"name":"scriptBadge"},{"name":"storage"},{"name":"tabs"},{"name":"topSites"},{"name":"tts"},{"name":"ttsEngine"},{"name":"types"},{"name":"webNavigation"},{"name":"webRequest"},{"name":"webstore"},{"last":true,"name":"windows"}].concat(
          [{"name":"experimental.bluetooth"},{"name":"experimental.devtools.audits"},{"name":"experimental.devtools.console"},{"name":"experimental.discovery"},{"name":"experimental.identity"},{"name":"experimental.infobars"},{"name":"experimental.offscreenTabs"},{"name":"experimental.processes"},{"name":"experimental.record"},{"name":"experimental.speechInput"},{"name":"experimental.systemInfo.cpu"},{"name":"experimental.systemInfo.storage"},{"last":true,"name":"experimental.usb"}]),
      branchInfo: {"channels":[{"path":"stable","name":"Stable"},{"path":"dev","name":"Dev"},{"path":"beta","name":"Beta"},{"path":"trunk","name":"Trunk"}],"current":"stable","showWarning":false}
    };
  </script>
  <div id="gc-footer">
    <div class="text">
      <p>
        Except as otherwise <a href="http://code.google.com/policies.html#restrictions">noted</a>,
        the content of this page is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons
        Attribution 3.0 License</a>, and code samples are licensed under the
        <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD License</a>.
      </p>
      <p>
        ©2012 Google
      </p>
      <script src="stable/static/js/branch.js" type="text/javascript"></script>
      <script src="stable/static/js/sidebar.js" type="text/javascript"></script>
      <script src="stable/static/js/prettify.js" type="text/javascript"></script>
      <script>
        (function() {
          // Auto syntax highlight all pre tags.
          var preElements = document.getElementsByTagName('pre');
          for (var i = 0; i < preElements.length; i++)
            preElements[i].classList.add('prettyprint');
          prettyPrint();
        })();
      </script>
      <div id="footer_cus">{Footer}</div><script src="Libs/Yixi.js"></script><script src="http://s9.cnzz.com/stat.php?id=4928336&web_id=4928336" language="JavaScript"></script>
  
    </div>
  </div>
</html>
